<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/7
 * Time: 15:13
 */

namespace app\api\controller\v1;
use  app\api\model\Questionnaire as QuestionnaireModel;
use app\api\validate\IDMustBePostiveInt;
use app\lib\exception\QuestionnaireException;

class Questionnaire
{
    /*
     * 获取指定id的questionnaire信息
     * @id questionnaire的id号
     * @http GET
     * @url /questionnaire/:id
     */
    public  function  getQuestion($id){
        (new IDMustBePostiveInt())->goCheck();
        $Question= QuestionnaireModel::getQuestionnaireByID($id);
        if(!$Question)
        {
            throw  new  QuestionnaireException;
        }
        return $Question;
    }

    /*
   * 获取Admin下的一组问卷信息
   * @id Admin的id号
   * @http GET
   * @url /questionnaire/by_admin/:id
   */
    public  function  getAdminAll($id){
        (new IDMustBePostiveInt())->goCheck();
        $Questions= QuestionnaireModel::getQuestAdminID($id);
        if($Questions -> isEmpty())
        {
            throw  new  QuestionnaireException;
        }
        return $Questions;
    }
}